package com.yuqingxin.redisCacheApi.common.redisCache;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author yuqingxin
 * */
@Service
public class RedisCacheService {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    public String get(String key){
        return redisTemplate.opsForValue().get(key);
    }

    public void set(String key, String value){
        redisTemplate.opsForValue().set(key,value,60, TimeUnit.SECONDS);
    }

    public void set(String key, String value, long seconds){
        redisTemplate.opsForValue().set(key,value,seconds, TimeUnit.SECONDS);
    }

    public void set(String key, String value, long seconds, TimeUnit timeUnit){
        redisTemplate.opsForValue().set(key,value,seconds, timeUnit);
    }
}
